<?php
/**
 * Created by PhpStorm.
 * User: superxing-cto
 * Date: 17/1/9
 * Time: 12:05
 */

namespace App\Models;

/**
 * Class Follow
 * @property integer user_id 用户id
 * @property integer type_id 类型id
 * @property string type 类型
 * @property boolean is_push 是否接收推送
 * @property boolean is_mutual 是否互相关注
 */
class Follow extends ApplicationModel
{
    protected $fillable = [
        'user_id', //用户id
        'type_id', //类型id
        'type', //类型
        'is_push', //是否接收推送
        'is_mutual', //是否互相关注
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function followUser()
    {
        return $this->belongsTo(User::class, 'type_id');
    }

    public function send_msg($content, $url = null)
    {
        //发送推送
        $message = new Message();
        $message->user_id = $this->type_id;
        $message->content = $content;
        $message->icon = Message::ICON;
        $message->url_schema = $url;
        $message->type_id = $this->id;
        $message->save();

        $message->pushMsg($this->type_id, $content);
    }
}
